package com.kb.erp.mapper.sqlServer;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.kb.erp.entity.pcbout.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper


@DS("slave-1")
public interface PCBOutMapper {


    List<LastRecord> getMaterialRecordsByK3Nos(@Param("k3Nos") List<String> k3Nos,String workshopId);

    int insertRecord(LastRecord record);


    @Select({
            "<script>",
            "SELECT A.FDEPTID as rkey, A.FNUMBER 部门编码, A.FDEPTPROPERTY, B.FNAME 部门名称, A.FDOCUMENTSTATUS, A.FFORBIDSTATUS, C.FNUMBER, D.FNAME 组织名称",
            "FROM AIS20160407095349.DBO.T_BD_DEPARTMENT A WITH (NOLOCK)",
            "LEFT JOIN AIS20160407095349.DBO.T_BD_DEPARTMENT_L B WITH (NOLOCK) ON A.FDEPTID = B.FDEPTID",
            "LEFT JOIN AIS20160407095349.DBO.T_ORG_ORGANIZATIONS C WITH (NOLOCK) ON A.FUSEORGID = C.FORGID",
            "LEFT JOIN AIS20160407095349.DBO.T_ORG_ORGANIZATIONS_L D WITH (NOLOCK) ON A.FUSEORGID = D.FORGID AND D.FLOCALEID='2052'",
            "WHERE D.FNAME='惠州市金百泽电路科技有限公司' and B.FNAME!='制-钻孔' and B.FNAME!='制造部-线路' AND A.FNUMBER NOT LIKE 'BM%' AND A.FFORBIDSTATUS='A' ",
//            "WHERE C.FNUMBER IN ('128') AND A.FDEPTPROPERTY IN ('4866f13a3a3940b9b2fe47895a6e7cbe')",
            "</script>"
    })
    List<K3WorkShop> getWorkShops();


    @Select({
            "<script>",
            "SELECT TOP 1 B.FNAME",  // Use TOP 1 to limit the result to just one row
            "FROM AIS20160407095349.DBO.T_BD_DEPARTMENT A WITH (NOLOCK)",
            "LEFT JOIN AIS20160407095349.DBO.T_BD_DEPARTMENT_L B WITH (NOLOCK) ON A.FDEPTID = B.FDEPTID",
            "LEFT JOIN AIS20160407095349.DBO.T_ORG_ORGANIZATIONS C WITH (NOLOCK) ON A.FUSEORGID = C.FORGID",
            "LEFT JOIN AIS20160407095349.DBO.T_ORG_ORGANIZATIONS_L D WITH (NOLOCK) ON A.FUSEORGID = D.FORGID AND D.FLOCALEID='2052'",
            "WHERE D.FNAME='惠州市金百泽电路科技有限公司'",
            "AND A.FDEPTID=#{id}",
            "</script>"
    })
    String getWorkShopName(String id);


    @Select({
            "<script>",
            "SELECT A.FNUMBER AS 部门编码,A.FDEPTPROPERTY as deptproperty",
            "FROM AIS20160407095349.DBO.T_BD_DEPARTMENT A WITH (NOLOCK)",
            "WHERE A.FDEPTID = #{rkey}",
            "</script>"
    })
    K3WorkShop getDepartmentNumberByRkey(String rkey);



    List<QueryVO> selectWorkOrders(QueryTO to);

    List<Material> queryBomList(@Param("plate") String plate, @Param("type")String type);

    Material queryBomByNo(@Param("no") String no);
    List<Material> queryList();


    Material queryBomByItem(@Param("type") String type,@Param("plate") String plate,@Param("copper") String copper);


    @Delete({
            "<script>",
            "DELETE FROM MSSQLLIVE.dbo.month_use;",  // 清空表格数据
            "</script>"
    })
    void clearMonthUseTable();



    @Insert({
            "<script>",
            "INSERT INTO MSSQLLIVE.dbo.month_use (workshop, code, qty) VALUES ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.workshop}, #{item.code}, #{item.qty})",
            "</foreach>",
            "</script>"
    })
    void insertList(@Param("list") List<MonthUse> list);



    void issuanceInsertList(@Param("list") List<MonthUse> list);


}
